The technology described herein relates to a method of and an apparatus for performing texture mapping in graphics processing systems.
It is common in graphics processing systems to generate colours for sampling positions in a render output (e.g. image to be displayed) by applying so-called textures or texture data to the surfaces to be drawn. Such textures are typically applied by storing an array of texture data elements (“texels”), each representing given texture data (such as colour, luminance, and/or light/shadow, etc. values), and then mapping the texels onto the corresponding samples, such as (and, indeed, typically) a set of sampling positions, for the render output in question (e.g. image to be displayed).
Thus a graphics texture will typically be configured as an array of data elements (texture elements (texels)), each having a corresponding set of texture data stored for it. The texture data for a given position within the texture is then determined by sampling the texture at that position (e.g. using a bilinear filtering process).
FIG. 1 shows an exemplary graphics processor (graphics processing unit (GPU)) 100 that can perform texture mapping.
As shown in FIG. 1, the GPU 100 comprises data processing circuitry that implements a graphics processing pipeline. The pipeline includes, inter alia, a rasterizer 102 and a renderer in the form of a programmable (fragment) shader core 104. The pipeline uses a buffer 106 (e.g. in external memory 108) for storing an output array (e.g. frame or image to be displayed).
The GPU 100 further comprises a texture mapper 110, and the memory 108 will also store, inter alia, graphics textures to be used by the GPU 100 when performing texture mapping operations.
In this system, the rasterizer 102 will rasterize input primitives into individual graphics fragments for processing. To do this, the rasterizer 102 rasterizes the primitives to sampling positions representing the render output, and generates graphics fragments representing appropriate sampling positions for rendering the primitives. Each fragment may represent a single sampling position or a set of plural sampling positions. The fragments generated by the rasterizer 102 are then sent onwards to the fragment shader (renderer) 104 for shading.
The fragment shader 104 executes shader programs for the fragments issued by the rasterizer 102 in order to render (shade) the fragments. The fragments are processed using execution threads in the shader core, with the threads executing the shader program(s) that are to be used to process the fragments. A thread is executed for each sampling position that is to be shaded.
A shader program may include texturing instructions for texture mapping operations that are required to be executed by the texture mapper 110.
When a texturing instruction is encountered by the fragment shader 104, a texturing instruction is sent from the fragment shader 104 to the texture mapper 110, requesting the texture mapper 110 to perform a texturing operation.
When requested by the fragment shader 104 to perform a texture mapping operation, the texture mapper 110 reads textures from the memory 108 (as required), performs the texture mapping operation, and returns a (e.g. RGB colour) value sampled from the texture back to the fragment shader 104, for use when shading the fragment and sampling position(s) in question.
The “shaded” fragment sampling positions from the fragment shader 104 are then stored as part of the output render target in the buffer 106, e.g. in the memory 108, e.g. for subsequent post-processing or display.
FIG. 2 shows an exemplary texture mapper (texture mapping apparatus) 110 in more detail.
As shown in FIG. 2, the texture mapper 110 includes a number of processing stages (circuits), including an input request stage (circuit) 200 that accepts texture mapping operation requests from a renderer (e.g. the fragment shader 104 in FIG. 1). This is followed by a coordinate calculation stage (circuit) 201 that, for example, will convert an arbitrary coordinate included with a texture mapping operation request into an appropriate canonical coordinate between 0.0 and 1.0 to be used when sampling the texture.
There is then, if necessary, a level of detail (LOD) computation stage (circuit) 202, that can determine the level of detail at which the texture is to be sampled for the texture mapping operation (e.g. that selects the mipmap levels to use and how to filter between them in the case where the texture is in the form of mipmaps). This level of detail computation may not be necessary, for example where the fragment shader program itself can explicitly indicate the level of detail to be used, or a texture is not stored in the form of mipmaps.
There is then a texel selection stage (circuit) 203, which uses the coordinate determined by the coordinate calculation stage 201 to determine the actual texels (texture data elements) in the texture (and, if appropriate, the determined mipmap levels in the texture) to be used for the texture mapping operation.
The required texels (their data) are then fetched by a cache lookup stage (circuit) 204.
As shown in FIG. 2, although the texture data will be stored in the memory system 108, when that texture data is needed by the texture mapper 110, the texture data required for the texturing operation will be fetched from the memory 108 where it is stored, and first loaded into a texture cache 205 of or accessible to the texture mapper 110, with the texture mapper 110 then reading the texture data (by the cache lookup circuit 204) from the texel cache 205 for use.
As shown in FIG. 2, the texture mapper 110 may accordingly comprise a texel loader (a texel loading circuit) 206 that is operable to load data of texels from textures stored in the memory 108 for storing in the texel cache 205. There may also be a decompressor (decoder) stage (circuit) 207 that can decompress (decode) textures that are stored in a compressed (encoded) format in the memory system 108 before storing the texel values in the texel cache 205.
Once the required texels (texel data values) have been fetched from the texel cache 205, they are used in the required texture filtering operation by a texture filtering stage (circuit) 208 to generate an appropriate output result for the texture position (coordinate) being sampled, which output result is then appropriately packaged and returned to the fragment shader by an output result stage (circuit) 209. The texture filtering circuit 208 may, for example, perform any desired form of filtering using the fetched texel values, such as bilinear or trilinear, or any other form of filtering, to generate the desired filtered sample result.
The Applicants believe that there is scope for improvements to the performance of texture mapping in graphics processing systems.
Like numerals are used for like features in the drawings where appropriate.